package com.youshang520i.controller;

import com.google.common.base.Charsets;
import com.support.annotation.LocalRateLimiter;
import com.youshang520i.model.CarModel;
import com.youshang520i.model.StudentModel;
import com.youshang520i.service.IndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.Map;

/**
 * @author youshang
 */
@RestController
@RequestMapping("/index")
public class IndexController {
    @Autowired
    private IndexService indexService;

    @LocalRateLimiter(fallback = "error")
    @RequestMapping(value = "/query",method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    public String query(@RequestBody CarModel model) {
        String welcome = indexService.welcome();
        System.out.println("welcome: "+welcome);
        return welcome;
//        return "hello world！！！";
    }

    public String error() {
        System.out.println("限流了！！！！");
        return "error!!!!";
    }


}
